import requests   # 导包

# 1. 调用get方法，发送 获取验证码的请求，获取响应结果
resp_v = requests.get(url="http://tpshop-test.itheima.net/index.php?m=Home&c=User&a=verify")

# 2. 从获取验证码的响应结果中，提取cookie
login_cookies = resp_v.cookies

# 3. 调用post方法，访问登录的接口，设置url, header, body, 注意并且携带cookie
login_url = "http://tpshop-test.itheima.net/index.php?m=Home&c=User&a=do_login"
login_header = {"Content-Type": "application/x-www-form-urlencoded"}
login_body = {"username": "13012345678", "password": "123456", "verify_code": "8888"}
resp_login = requests.post(url=login_url, headers=login_header, data=login_body, cookies=login_cookies)
print("resp_login=", resp_login.json())
# 4. 调用get方法，发送 查看我的订单请求，注意设置携带cookie,打印结果
order_url = "http://tpshop-test.itheima.net/home/Order/order_list.html"
resp_order = requests.get(url=order_url, cookies=login_cookies)
print("resp_order=", resp_order.text)


# import requests
# # 1. 调用get方法，发送 获取验证码的请求，获取响应结果
# resp_v = requests.get("http://tpshop-test.itheima.net/index.php?m=Home&c=User&a=verify")
# #print("resp_v=",resp_v.text)
# # 2. 从获取验证码的响应结果中，提取cookie
# my_cookie = resp_v.cookies
# # 3. 调用post方法，访问登录的接口，设置url, header, body, 注意并且携带cookie
# login_url = "http://tpshop-test.itheima.net/index.php?m=Home&c=User&a=do_login"
# login_header ={"Content-Type":"application/x-www-form-urlencoded"}
# login_body = {"username":"13012345678","password":"123456","verify_code":"8888"}
# resp_login = requests.post(url=login_url,headers=login_header,data=login_body,cookies=my_cookie)
# print("resp_login=",resp_login.json())
# # 4. 调用get方法，发送 查看我的订单请求，注意设置携带cookie,打印结果
# order_url = "http://tpshop-test.itheima.net/home/Order/order_list.html"
# resp_order = requests.get(url=order_url,cookies=my_cookie)
# print("resp_order=",resp_order.text)
